
#   cat("sumVariations: \n")
#   for (sv in 1:dim(sumVariations)[1]) { 
#     cat(sumVariations[sv,],"\n")
#   }

#   library(e1071) 
#   for (sv in 1:length(sumVariations)) { 
# #     combs(1:4,2)
# #     print(sumVariations[[sv]])
#     multiset = sumVariations[sv,]
#     starPerms <- unique(matrix(multiset,length(multiset)/K,K))
#     #   starPerms <- unique(apply(matrix(multiset[permutations(length(multiset))], 
#     #         ncol=length(multiset)), 1, paste, sep="", collapse="")) 
#   }
#   return(starPerms)
#======================================================================================
#==================================================================
# StarsAndBars <- function(x,m) {
# require(combinat) 
# if (is.numeric(x) && length(x) == 1 && x > 0 && trunc(x) == x) 
#   x <- seq(x) 
# temp <- combn(x, m) 
# if ( isTRUE(all.equal(m,1)) ) { 
#   P <- temp 
# } else if (isTRUE(all.equal(m, length(x)))) { 
#   temp <- matrix(x, ncol = 1) 
#   P <- array(unlist(permn(temp[, 1])), dim = c(m, factorial(m))) 
# } else { 
#   k <- dim(temp)[1] 
#   n <- dim(temp)[2] 
#   P <- array(unlist(permn(temp[, 1])), dim = c(k, factorial(k))) 
#   for (i in 2:n) { 
#     a <- temp[, i] 
#     perms <- array(unlist(permn(a)), dim = c(k, factorial(k))) 
#     P <- cbind(P, perms) 
#   } 
# } 
# return(P) 
# } 
#==================================================================
#   # Generate a lookup table with N buckets and K balls
#   P1 = pascal(max(K+1,N+1))
#   P = P1[1:N,]
#   
#   numstates = P[N,]
#   # ith element gives number of states for N buckets and (i-1) balls
#   
#   # addermat is a matrix of "raw adder" vectors:
#   addermat = fliplr(eye(N))
#   
#   # init
#   look = matrix(zeros(1,N),1,N)
#   
#   # Put C = max(c)...the number of balls is K = C-1, so K-1 = C-2
#   blocksize <- matrix(integer(K*N),K,N)
#   cellblock <- list()
#   for (c in 1:K) {
#     for (x in 1:N) {
#       blocksize[c,x] = choose(c+x-2,c-1)
#       temp = blocksize[c,x]
#       cellblock[[x]] = look[1:temp,] + repmat(addermat[x,],temp,1)
#     }
#     rm(look)
#     look <- c(cellblock,recursive=TRUE)
#     look <- matrix(look,length(look)/N,N)
#   }
#   return(look)
# }